package 多线程;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Author: 李佳芬
 * @Description: 练习使用多线程下载图片
 * @DateTime: 2023/3/21 15:29
 **/
public class TestThread2 implements Runnable {
    private String name;
    private String url;

    public TestThread2(String url, String name) {
        this.name = name;
        this.url = url;
    }

    @Override
    public void run() {

        Download.DownloadImg(name, url);
        System.out.println("下载了" + name);
    }

    public static void main(String[] args) {
     /*   TestThread2 t1 = new TestThread2("https://www.bilibili.com/video/BV1bM4y1r7TP?t=4.3","蓝眼睛的猫女孩.MP4");
       *//* TestThread2 t2 = new TestThread2("https://pic.netbian.com/uploads/allimg/220802/231950-165945359015c6.jpg","阿狸 cosplay美女4k.png");*//*
       *//* TestThread2 t3 = new TestThread2("https://pic.netbian.com/uploads/allimg/230318/234848-1679154528deae.jpg","通向未来的列车.png");*//*
        new Thread(t1).start();
        *//*new Thread(t2).start();*//*
        *//*new Thread(t3).start();*/
    }
}
class Download{
    public static void DownloadImg(String name,String url){

        try {
            FileUtils.copyURLToFile(new URL(url),new File( name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("下载器异常");
        }

    }
}
